
#ifndef __VOL_SUPPER_BUTTON_H__
#define __VOL_SUPPER_BUTTON_H__

#define VSBTN_USE_SOUND

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

// Return values
#ifndef VSBTN_OK
#define VSBTN_OK  0
#endif
#ifndef VSBTN_INVALIDRESOURCE
#define VSBTN_INVALIDRESOURCE  1
#endif
#ifndef VSBTN_FAILEDMASK
#define VSBTN_FAILEDMASK  2
#endif
#ifndef VSBTN_INVALIDINDEX
#define VSBTN_INVALIDINDEX  3
#endif
#ifndef VSBTN_INVALIDALIGN
#define VSBTN_INVALIDALIGN  4
#endif
#ifndef VSBTN_BADPARAM
#define VSBTN_BADPARAM  5
#endif
#ifndef VSBTN_INVALIDPRESSEDSTYLE
#define VSBTN_INVALIDPRESSEDSTYLE  6
#endif

////////////////////////////

#define ST_ALIGN_HORIZ          0  // bitmap on the left, text on the right
#define ST_ALIGN_VERT           1  // bitmap on the top, text on the bottom
#define ST_ALIGN_HORIZ_RIGHT    2  // bitmap on the right, text on the left
#define ST_ALIGN_OVERLAP        3  // bitmap on the same space as text

#define VSBTN_COLOR_FG_OUT       0  // Text color when mouse is OUTside
#define VSBTN_COLOR_BK_OUT       1  // Background color when mouse is OUTside
#define VSBTN_COLOR_FG_IN        2  // Text color when mouse is INside
#define VSBTN_COLOR_BK_IN        3  // Background color when mouse is INside
#define VSBTN_COLOR_FG_FOCUS     4  // Text color when the button is focused
#define VSBTN_COLOR_BK_FOCUS     5  // Background color when the button is focused
#define VSBTN_MAX_COLORS     (VSBTN_COLOR_BK_FOCUS + 1)

#define VSBTN_PRESSED_LEFTRIGHT  0  // Pressed style from left to right (as usual)
#define VSBTN_PRESSED_TOPBOTTOM  1  // Pressed style from top to bottom

////////////////////////////

class CVolSupperButton : public CButton
{
public:
    CVolSupperButton ();
    ~CVolSupperButton ();

    //{{AFX_VIRTUAL(CVolSupperButton)
    public:
    virtual void DrawItem (LPDRAWITEMSTRUCT lpDrawItemStruct);
    virtual BOOL PreTranslateMessage (MSG* pMsg);
    protected:
    virtual void PreSubclassWindow ();
    //}}AFX_VIRTUAL

public:
    void SetDefaultColors ();

    DWORD SetCheck (int nCheck, BOOL bRepaint = TRUE);
    int GetCheck ();

    void SetTooltipText (LPCTSTR lpszText, BOOL bActivate = TRUE);
    void SetPressedStyle (INT nStyle);
    void SetBitmap (int nIndex, HBITMAP hBitmap, COLORREF crTransColor, BOOL bRepaint = TRUE);

    POINT m_ptImageOrg;
    POINT m_ptPressedOffset;

public:
    //{{AFX_MSG(CVolSupperButton)
    afx_msg void OnKillFocus(CWnd* pNewWnd);
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg BOOL OnClicked();
    afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
    afx_msg void OnEnable(BOOL bEnable);
    afx_msg void OnCancelMode();
    afx_msg UINT OnGetDlgCode();
    afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
    //}}AFX_MSG

    virtual DWORD OnDrawBackground(CDC* pDC, LPCRECT pRect);
    virtual DWORD OnDrawBorder(CDC* pDC, LPCRECT pRect);

    BOOL m_bIsXPButton;
    BOOL m_bIsFlat;  // Is a flat button?
    BOOL m_bMouseOnButton;  // Is mouse over the button?
    BOOL m_bIsPressed;  // Is button pressed?
    BOOL m_bIsFocused;  // Is button focused?
    BOOL m_bIsDisabled;  // Is button disabled?
    BOOL m_bIsDefault;  // Is default button?
    BOOL m_bIsCheckBox;  // Is the button a checkbox?
    INT m_nAlign;  // Align mode
    BOOL m_bDrawBorder;  // Draw border?
    BOOL m_bDrawFlatFocus;  // Draw focus rectangle for flat button?
    BOOL m_bUseDefaultColor;
    COLORREF m_crColors [VSBTN_MAX_COLORS];  // Colors to be used

public:
    LRESULT OnSetCheck (WPARAM wParam, LPARAM lParam);
    LRESULT OnGetCheck (WPARAM wParam, LPARAM lParam);
    LRESULT OnSetStyle (WPARAM wParam, LPARAM lParam);
    LRESULT OnMouseLeave (WPARAM wParam, LPARAM lParam);

    void CancelHover ();
    void PrepareImageRect (BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage);
    HBITMAP CreateBitmapMask (HBITMAP hSourceBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTransColor);
    virtual void DrawTheBitmap (CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled);
    virtual void DrawTheText (CDC* pDC, LPCTSTR lpszText, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled);

    void InitToolTip ();

    CToolTipCtrl m_ToolTip;  // Tooltip

    BOOL m_bAlwaysTrack;  // Always hilight button?
    int m_nCheck;  // Current value for checkbox
    UINT m_nTypeStyle;  // Button style

    typedef struct _STRUCT_BITMAPS
    {
        HBITMAP hBitmap;  // Handle to bitmap
        DWORD dwWidth;  // Width of bitmap
        DWORD dwHeight;  // Height of bitmap
        HBITMAP hMask;  // Handle to mask bitmap
    } STRUCT_BITMAPS;

    STRUCT_BITMAPS m_csBitmaps [3];  // 0: in;  1: out;  2: disabled

#ifdef VSBTN_USE_SOUND
    BOOL m_blUseStandardSound;
    INT m_nSoundDataResID [2];  // Index 0 = Over 1 = Clicked

    void MPlaySound (int nIndex);
#endif

    DECLARE_MESSAGE_MAP()
};

#endif
